answersLogoWhite

0

AllQ&AStudy Guides
Best answer

Yes. The following template examples will work for all unsigned integers of length 1, 2, 4 and 8 bytes.

#include <type_traits> // for std::is_unsigned

template<class T>

T circular_shift_left( register T x )

{

static_assert( std::is_unsigned<T>::value, "circular_shift_left(T): T must be unsigned!\n" );

T bit = x;

switch( sizeof( x ))

{

case(1): bit &= (T) 0x80; break;

case(2): bit &= (T) 0x8000; break;

case(4): bit &= (T) 0x80000000; break;

case(8): bit &= (T) 0x8000000000000000; break;

default: assert( 0 );

}

x <<= 1;

x |= bit ? 1 : 0;

return( x );

}

template<class T>

T circular_shift_right( register T x )

{

static_assert( std::is_unsigned<T>::value, "circular_shift_right(T): T must be unsigned!\n" );

T bit = x & (T) 0x1;

switch( sizeof( x ))

{

case(1): bit = bit ? (T) 0x80 : 0x0; break;

case(2): bit = bit ? (T) 0x8000 : 0x0; break;

case(4): bit = bit ? (T) 0x80000000 : 0x0; break;

case(8): bit = bit ? (T) 0x8000000000000000 : 0x0; break;

default: assert( 0 );

}

x >>= 1;

x |= bit;

return( x );

}

This answer is:
Related answers

Yes. The following template examples will work for all unsigned integers of length 1, 2, 4 and 8 bytes.

#include <type_traits> // for std::is_unsigned

template<class T>

T circular_shift_left( register T x )

{

static_assert( std::is_unsigned<T>::value, "circular_shift_left(T): T must be unsigned!\n" );

T bit = x;

switch( sizeof( x ))

{

case(1): bit &= (T) 0x80; break;

case(2): bit &= (T) 0x8000; break;

case(4): bit &= (T) 0x80000000; break;

case(8): bit &= (T) 0x8000000000000000; break;

default: assert( 0 );

}

x <<= 1;

x |= bit ? 1 : 0;

return( x );

}

template<class T>

T circular_shift_right( register T x )

{

static_assert( std::is_unsigned<T>::value, "circular_shift_right(T): T must be unsigned!\n" );

T bit = x & (T) 0x1;

switch( sizeof( x ))

{

case(1): bit = bit ? (T) 0x80 : 0x0; break;

case(2): bit = bit ? (T) 0x8000 : 0x0; break;

case(4): bit = bit ? (T) 0x80000000 : 0x0; break;

case(8): bit = bit ? (T) 0x8000000000000000 : 0x0; break;

default: assert( 0 );

}

x >>= 1;

x |= bit;

return( x );

}

View page

If the period is ' t ', then the frequency is 1/t .

View page

The definiton of period (T) . Is T = 1/f ; Therefore if you know that the period is 2.5

View page

The period (T) of a circle is represented by the equation: T=1/F, where F is the frequency.

View page

NO! It lived in the Cretaceous period, litteraly

View page
Featured study guide

The price of 1g of Yttrium

How do you convert 100 millimeters to meters

What is mega meter

How High would you have to stack 100 dollar bills to make 1 billion dollars

➡️
See all cards
3.0
4 Reviews
More study guides
No Reviews

No Reviews
Search results